from app import db
from datetime import datetime, date

class DailyActivity(db.Model):
    __tablename__ = 'daily_activities'
    
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    record_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    
    # 运动数据
    steps = db.Column(db.Integer)  # 步数
    exercise_minutes = db.Column(db.Integer)  # 运动时长 (分钟)
    calories_burned = db.Column(db.Float)  # 消耗卡路里
    
    # 睡眠数据
    sleep_hours = db.Column(db.Float)  # 睡眠时长 (小时)
    sleep_quality = db.Column(db.String(20))  # 睡眠质量: excellent/good/fair/poor
    
    # 饮食记录
    water_intake = db.Column(db.Float)  # 饮水量 (L)
    notes = db.Column(db.Text)  # 备注
    
    def to_dict(self):
        return {
            'id': self.id,
            'user_id': self.user_id,
            'record_date': self.record_date.isoformat(),
            'steps': self.steps,
            'exercise_minutes': self.exercise_minutes,
            'calories_burned': self.calories_burned,
            'sleep_hours': self.sleep_hours,
            'sleep_quality': self.sleep_quality,
            'water_intake': self.water_intake,
            'notes': self.notes
        }